define(["cmn","lib/diqye-pager"],function(cmn){
	var ejs=cmn.ejs("19911204/7/leaveNote");
	ejs.set("main","main");
	ejs.set("list","list");
	return {
		init:function(){
			var _=this;
			_.renderMain();
		},
		renderMain:function(){
			var _=this;
			_.el.html(ejs.main,function(){
				var reviewModel,pageDiv=_.el.find("#review1027");
					reviewModel={
					action:"Blog_queryReview",
					params:{
						currentIndex:0,
						pageSize:10,
						target:-7
					}
				};
				var pagefn=function(data){
					if(data.count<=10)return;
					// 分页
					_.el.find("#pagination1027").pagination({
						ejs:cmn.cmn_ejs.pagination,
						param:{
							count:data.count,
							pageSize:10
						},
						callback:function(i){
							reviewModel.params.currentIndex=(i-1)*10;
							_.renderReview(pageDiv,reviewModel);
						}
					});	
				};
				_.renderReview(pageDiv,reviewModel,pagefn);
				_.el.find("#revew1027").on("click",function(){
					if(_.el.find("#form1027").validate()){
						var model={
							action:"Blog_addReview",
							params:{
								target:-7,
								content:_.el.find("#revew_countent_1027").val()
							}
						};
						cmn.lbox.show();
						cmn.post(model).then(function(data){
							cmn.lbox.hide();
							reviewModel.params.currentIndex=0;
							_.renderReview(pageDiv,reviewModel,pagefn);
							_.el.find("#form1027").reset();
						});
					}
				});
				_.el.find("#revew_countent_1027").on("keyup",function(e){
					if(e.keyCode==13)_.el.find("#revew1027").trigger('click');
				});
			});
		},
		renderReview:function(div,reviewModel,callback){
			var _=this;
			cmn.lbox.show();
			cmn.post(reviewModel).then(function(data){
				data.currentIndex=reviewModel.params.currentIndex;
				div.html(ejs.list,data);
				if(callback)callback(data);
				cmn.lbox.hide();
			});
		}
	}
});